package com.xm.api.config;

import com.alibaba.cloud.sentinel.feign.SentinelFeign;
import feign.Feign;
import feign.Logger;
import feign.Request.Options;
import feign.Retryer;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
@EnableFeignClients(basePackages = "com.xm.api.client")
public class RequestIdRelayConfiguration {

    @Bean
    public Options options() {
        // 使用推荐的构造函数设置连接超时和读取超时
        return new Options(1, TimeUnit.SECONDS, 5, TimeUnit.SECONDS, true);
    }

    @Bean
    public Logger.Level feignLoggerLevel() {
        // 设置Feign的日志级别为FULL
        return Logger.Level.FULL;
    }

    @Bean
    Retryer retryer(){
        // 配置默认重试器
        return new Retryer.Default();
    }

    @Bean
    public Feign.Builder feignSentinelBuilder() {
        // 创建SentinelFeign.Builder实例，用于构建Feign客户端
        return SentinelFeign.builder();
    }
}
